<?php
/**
 * 运费模板模块
 * @author ezhu <ezhu@jipukeji.com>
 */

namespace Shop\Model;

use Think\Model;

class TransportModel extends Model{
    
    protected $tableName = 'transport';
    
    protected $_validate = array(
            array('title','require','请填写运费模板名称！'),
            array('price_type','require','请计算方式！'),
            array('express_start','require','请填写默认运费！'),
            array('express_postage','require','请填写默认运费！'),
            array('express_plus','require','请填写默认运费！'),
            array('express_postageplus','require','请填写默认运费！'),
    );
    
    
    /**
     * 运费模板列表
     * @param number $store_id
     */
    public function getList($store_id=0){
        if(empty($store_id)){
            return array();
        }
        $map = array();
        $map['store_id'] = $store_id;
        $data = M('Transport')->where($map)->select();
        $pids = array_column($data, 'id');
        if(!empty($pids)){
            $eMap['transport_id'] = array('in',$pids);
            $eMap['status'] = array('egt',0);
            $extend = M('TransportExtend')->where($eMap)->select();
            $extend = arrKeyChange($extend,'transport_id',false);
            foreach($data as $key=>$val){
                $data[$key]['extend'] = $extend[$val['id']];
            }
        }
        return $data;
    }
    
    
}